2020-2021 Sunseeker Telemetry and Lighting System
timer_d_ex1_contCRR0.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // MSP430F51x2 Demo - TimerD0, Toggle P1.0, CCR0 Cont. Mode ISR, DCO SMCLK
34 //
35 // Description: Toggle P1.0 using software and TD_0 ISR. Toggles every
36 // 50000 SMCLK cycles. SMCLK provides clock source for TDCLK.
37 // During the TD_0 ISR, P1.0 is toggled and 50000 clock cycles are added to
38 // CCR0. TD_0 ISR is triggered every 50000 cycles. CPU is normally off and
39 // used only during TD_ISR. Toggle rate = 50000/1.045Mhz ~ 48ms.
40 // ACLK = n/a, MCLK = SMCLK = TDCLK = default DCO ~1.045MHz
41 //
42 // MSP430F51x2
43 // ---------------
44 // /|\| |
45 // | | |
46 // --|RST |
47 // | |
48 // | P1.0|-->LED
49 //
50 //******************************************************************************
51 
52 #include "driverlib.h"
53 
54 void main(void)
55 {
56  //Stop WDT
57  WDT_A_hold(WDT_A_BASE);
58 
59  //Set P1.0 to output direction
60  GPIO_setAsOutputPin(
61  GPIO_PORT_P1,
62  GPIO_PIN0
63  );
64 
65  //Start timer in continuous mode sourced by SMCLK
66  Timer_D_initContinuousModeParam initContparam = {0};
67  initContparam.clockSource = TIMER_D_CLOCKSOURCE_SMCLK;
68  initContparam.clockSourceDivider = TIMER_D_CLOCKSOURCE_DIVIDER_1;
69  initContparam.clockingMode = TIMER_D_CLOCKINGMODE_EXTERNAL_CLOCK;
70  initContparam.timerInterruptEnable_TDIE = TIMER_D_TDIE_INTERRUPT_DISABLE;
71  initContparam.timerClear = TIMER_D_DO_CLEAR;
72  Timer_D_initContinuousMode(TIMER_D0_BASE, &initContparam);
73 
74  Timer_D_startCounter(TIMER_D0_BASE,
75  TIMER_D_CONTINUOUS_MODE
76  );
77 
78  //Initiaze compare mode
79  Timer_D_clearCaptureCompareInterrupt(TIMER_D0_BASE,
80  TIMER_D_CAPTURECOMPARE_REGISTER_0);
81 
82 
83  Timer_D_initCompareModeParam initCompParam = {0};
84  initCompParam.compareRegister = TIMER_D_CAPTURECOMPARE_REGISTER_0;
85  initCompParam.compareInterruptEnable = TIMER_D_CAPTURECOMPARE_INTERRUPT_ENABLE;
86  initCompParam.compareOutputMode = TIMER_D_OUTPUTMODE_OUTBITVALUE;
87  initCompParam.compareValue = 50000;
88  Timer_D_initCompareMode(TIMER_D0_BASE, &initCompParam);
89 
90  __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, enable interrupts
91  __no_operation(); // For debugger
92 }
93 
94 // Timer0_D0 interrupt service routine
95 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
96 #pragma vector=TIMER0_D0_VECTOR
97 __interrupt
98 #elif defined(__GNUC__)
99 __attribute__((interrupt(TIMER0_D0_VECTOR)))
100 #endif
101 void TIMER0_D0_ISR(void)
102 {
103  //Toggle P1.0
104  GPIO_toggleOutputOnPin(
105 
106  GPIO_PORT_P1,
107  GPIO_PIN0
108  );
109 
110  //Add Offset to CCR0
111  Timer_D_setCompareValue(TIMER_D0_BASE,
112  TIMER_D_CAPTURECOMPARE_REGISTER_0,
113  5000
114  );
115 }
116 
__no_operation()
void TIMER0_D0_ISR(void)
void main(void)